package com.anticode.utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Santiago J. Franzani
	 */
	public class mcUtil 
	{
		
		public function mcUtil() 
		{
			
		}
		public static function stopChildrenOf(clip:DisplayObjectContainer,stopTimeline:Boolean = false):void
		{
		  var i:int = clip.numChildren;
		  var child:DisplayObject;
		  while (i--)
		  {
			child = clip.getChildAt(i);
			if (child is MovieClip) (child as MovieClip).stop();
			if (child is DisplayObjectContainer) 
				stopChildrenOf(child as DisplayObjectContainer);
		  }
		  if (stopTimeline && clip is MovieClip)(clip as MovieClip).stop();
		}	
		public static function stopChildrenFrame1(clip:DisplayObjectContainer,stopTimeline:Boolean = false):void
		{
		  var i:int = clip.numChildren;
		  var child:DisplayObject;
		  while (i--)
		  {
			child = clip.getChildAt(i);
			if (child is MovieClip) (child as MovieClip).gotoAndStop(1);
			if (child is DisplayObjectContainer) 
				stopChildrenFrame1(child as DisplayObjectContainer);
		  }
		 if (stopTimeline && clip is MovieClip) (clip as MovieClip).gotoAndStop(1);
		}	
		public static function playAllChildrenOfFrame1(clip:DisplayObjectContainer,playClip:Boolean = false):void
		{
		  var i:int = clip.numChildren;
		  var child:DisplayObject;
		  while (i--)
		  {
			child = clip.getChildAt(i);
			if (child is MovieClip) (child as MovieClip).gotoAndPlay(1);
			if (child is DisplayObjectContainer) 
				playAllChildrenOf(child as DisplayObjectContainer);
		  }
		  if (playClip && clip is MovieClip)(clip as MovieClip).gotoAndPlay(1);
		}	
		
		public static function playAllChildrenOf(clip:DisplayObjectContainer,playClip:Boolean = false):void
		{
		  var i:int = clip.numChildren;
		  var child:DisplayObject;
		  while (i--)
		  {
			child = clip.getChildAt(i);
			if (child is MovieClip) (child as MovieClip).play();
			if (child is DisplayObjectContainer) 
				playAllChildrenOf(child as DisplayObjectContainer);
		  }
		  if (playClip && clip is MovieClip) (clip as MovieClip).play();
		}

	}

}